<?php
if($_SESSION['user_id_sess']=="") {
		echo "<script type='text/javascript'> window.location='index.php?signin&url=mylist'; </script>";
	}
require_once 'includes/class.phpmailer.php';

$userid=$_REQUEST['owner_id'];
 
$ownname =getUser($userid);

$selgrtcnt=mysql_query("select count(*) as grtcnt from tbl_feedback where comm_to='$userid' AND rate='1' ");
$rowgrtcnt=mysql_fetch_array($selgrtcnt);
$grtcnt=$rowgrtcnt['grtcnt'];

$selacpcnt=mysql_query("select count(*) as acpcnt from tbl_feedback where comm_to='$userid' AND rate='2'");
$rowacpcnt=mysql_fetch_array($selacpcnt);
$acpcnt=$rowacpcnt['acpcnt'];

$selnegcnt=mysql_query("select count(*) as negcnt from tbl_feedback where comm_to='$userid' AND rate='3'");
$rownegcnt=mysql_fetch_array($selnegcnt);
$negcnt=$rownegcnt['negcnt'];

//$selnotrans=mysql_query("select count(*) as notrans from tbl_feedback where comm_to='$userid' AND DATEDIFF(post_on,date('Y-m-d')<=12)");
//$rowtranscnt=mysql_fetch_array($selnotrans);
//$notrans=$rowtranscnt['notrans'];
//
//if($grtcnt!=0 && $negcnt!=0)
//$feedbackcnt=$grtcnt/($grtcnt+$negcnt);
//
//if($notrans!=0)
//$percentfeedback=(100*$feedbackcnt)/$notrans;
//else
//$percentfeedback=100;


?>

<script language="javascript">
  function funpostfeedback()
	{
		//alert("hi");
		if(document.getElementById("comment").value=="")
		{
			alert("Please enter comment.");
			return false;
		}
		else
		  return true;
	}

</script>
<style type="text/css">
	span#add-wishlist { color:#0000CC; padding:5px; font-size:12px; }	
</style>


<div id='panel'>
	
<div class="fulldiv" style="width:950px; margin:0px 0px 0px 5px;">

<div class="fulldiv" style="margin:10px 0px 0px 0px;">
	
<div style="float:left;"><strong class="orangehead">Feedback page</strong></div>

<p class="pro_ptag grey_txt">All the user's feedback to done.</p>

<div class="fulldiv">
<div id="other1_feedback_pending_merc" class="greytab_out" style="float:left; margin:0px 5px -8px 12px;">
	<div class="whttab_left">&nbsp;</div>
	<div class="whttab_repeat"><?=$ownname?>&nbsp;&nbsp;<?php
													$numTotalFeedback=mysql_num_rows(mysql_query("select * from tbl_feedback where comm_to='".$_REQUEST['owner_id']."'"));
													
													$sum_of_positive=mysql_fetch_array(mysql_query("select SUM(points) as total_positive from tbl_feedback where comm_to='".$_REQUEST['owner_id']."' and rate=1"));
                                                    $sum_of_negative=mysql_fetch_array(mysql_query("select SUM(points) as total_negative from tbl_feedback where comm_to='".$_REQUEST['owner_id']."' and rate=3"));													                                                    $totalTransaction=mysql_num_rows(mysql_query("select * from tbl_feedback where comm_to='".$_REQUEST['owner_id']."' and rate!=2"));
													
													$feedback_rate=($sum_of_positive['total_positive']+$sum_of_negative['total_negative'])/$totalTransaction;
													if($numTotalFeedback>0 && $totalTransaction>0)
													{
													echo number_format($feedback_rate,2).'%'. " (".$numTotalFeedback.")";
													}
													else if($numTotalFeedback==0 && $totalTransaction==0)
													{
													echo '100%'. " (0)";
													}
													else
													{
													echo '100%'. " (1)";
													}
													?></div>
	<div class="whttab_right">&nbsp;</div>
</div>
<?php /*?><p class="pro_ptag"><strong>Comments on this transaction </strong></p><?php */?>


<div class="fulldiv">
<div class="fullbox2_top">&nbsp;</div>
<div class="fullbox2_repeat">

<div class="fdbk_box"> 
	     <table width="100%" align="center" border="0">
		     <tr>
			     <td>
				     Feedback last 12 months <?php
													$numTotalFeedback2=mysql_num_rows(mysql_query("select * from tbl_feedback where comm_to='".$_REQUEST['owner_id']."'"));
													
													
													$sum_of_positive2=mysql_fetch_array(mysql_query("select SUM(points) as total_positive from tbl_feedback where comm_to='".$_REQUEST['owner_id']."' and rate=1"));
                                                    $sum_of_negative2=mysql_fetch_array(mysql_query("select SUM(points) as total_negative from tbl_feedback where comm_to='".$_REQUEST['owner_id']."' and rate=3"));													                                                    $totalTransaction2=mysql_num_rows(mysql_query("select * from tbl_feedback where comm_to='".$_REQUEST['owner_id']."' and rate!=2"));
													
													$feedback_rate2=($sum_of_positive2['total_positive']+$sum_of_negative2['total_negative'])/$totalTransaction2;
													if($numTotalFeedback2>0 && $totalTransaction2>0)
													{
													echo number_format($feedback_rate2,2).'%';
													}
													else if($numTotalFeedback2==0 && $totalTransaction2==0)
													{
													echo '100%';
													}
													else
													{
													echo '100%';
													}
													?> 
			     </td>
		     </tr>
		     <tr>
			     <td>
				     How is feedback calculated(?)
			     </td>
		     </tr>
	     </table>
</div>

</div>
<div class="fullbox2_bot">&nbsp;</div>
</div>

<div class="fulldiv">
<p class="pro_ptag"><strong>Recent Feedback Ratings(last 12 months)</strong></p>
<div class="fullbox2_top">&nbsp;</div>
<div class="fullbox2_repeat">

<div class="fdbk_box"> 
	  <table width="100%" align="center" border="0">
		<tr>
			<td>
				<table width="100%" border="0" >
				<tr>
				  <td colspan="3">Last 12 months				  </td>
				</tr>
				<tr>
					<td width="10%">
						<img src="images/tick_blue.png" />					</td>
					<td width="15%">
						Great					</td>
					<td width="75%">
						<?php echo $grtcnt; ?>					</td>
				</tr>
				<tr>
					<td width="10%">
						<img src="images/accept.png" />					</td>
				  <td width="15%">
					Acceptable				  </td>
				  <td>
					<?php echo $acpcnt; ?>				  </td>
				</tr>
				
				<tr>
					<td width="10%">
						<img src="images/delete.png" />					</td>
				  <td width="15%" >
					Negative				  </td>
				  <td>
					<?php echo $negcnt; ?>				  </td>
				</tr>
				</table>
			</td>
		</tr>
	</table>
</div>

</div>
<div class="fullbox2_bot">&nbsp;</div>
</div>

<div class="fulldiv">
<p class="pro_ptag"><strong>Selling other members products (<a href="#">3rd party selling</a>)</strong></p>
<div class="fullbox2_top">&nbsp;</div>
<div class="fullbox2_repeat">

<?php
$sqlSelItem="SELECT * FROM tbl_items where seller_id='$userid' AND owner_id!='$userid' ORDER BY item_id DESC";
$rstSelItem=mysql_query($sqlSelItem);				
$noSelItem=mysql_num_rows($rstSelItem);
?>
<div class="fdbk_box"> 
	  <table width="100%" align="center" border="0">
		<tr>
			<td>
				<p>Sales: <?php echo $noSelItem?></p>
			</td>
		</tr>
	</table>
</div>

</div>
<div class="fullbox2_bot">&nbsp;</div>
</div>

<div class="fulldiv">
<p class="pro_ptag"><strong>Feedback History</strong></p>
<div class="fullbox2_top">&nbsp;</div>
<div class="fullbox2_repeat">

<div class="fdbk_box"> 
	  <table width="100%" align="center" border="0">
		<tr>
			<td><table width="100%" border="0" >
			<?php
			$sqlFeedBackRecords="Select * from tbl_feedback where comm_to=$userid";
			$exeFeedBackRecords=mysql_query($sqlFeedBackRecords) or die(mysql_error());
			$numFeedBackRecords=mysql_num_rows($exeFeedBackRecords);
			if($numFeedBackRecords>0)
			{
			while($arrFeedBackRecords=mysql_fetch_array($exeFeedBackRecords)) {
			if($arrFeedBackRecords['rate']==1)
			{
			   $imgpath='<img src="images/tick_blue.png" />';
			}
			if($arrFeedBackRecords['rate']==2)
			{
			   $imgpath='<img src="images/accept.png" />';
			}
			if($arrFeedBackRecords['rate']==3)
			{
			   $imgpath='<img src="images/delete.png" />';
			}
			$productInfo=mysql_fetch_array(mysql_query("select * from tbl_product where product_id='".$arrFeedBackRecords['product_id']."'"));
			$userInfo=mysql_fetch_array(mysql_query("select * from tbl_users where user_id='".$arrFeedBackRecords['comm_by']."'"));
			$strDate=strtotime($arrFeedBackRecords['post_on']);
			?>
				<tr>
					<td width="5%" valign="top">
						<?php echo $imgpath?>					</td>
					<td width="25%">
						<?php echo stripslashes($arrFeedBackRecords['comment']);?><br /><strong><?php echo stripslashes($productInfo['product_name']);?></strong>					</td>
					<td width="19%">
						$<?php echo number_format($productInfo['product_price'],2);?><br /><strong><?php echo $userInfo['first_name']; ?></strong>					</td>
					<td width="35%"><?php echo date("m-d-Y",$strDate)?></td>
				</tr>
				<?php } } else { ?>
				<tr><td colspan="4" align="center"><font color="#FF0000">Records not found</font></td></tr>
				<?php } ?>
				</table>
			</td>
		</tr>
	</table>
</div>


</div>
<div class="fullbox2_bot">&nbsp;</div>
</div>



</div>

</div>

</div>
<br /> 